import {SET_IDENTITY,SET_SEX,SET_NAME,SET_CARD,SET_BIRTHDAY,SET_ALL} from '../actions/myAction'

let homeState = {
    sex:'',
    name:'',
    cardType:'',
    card:'',
    birthDay:'',
}

let TYPES = {
    // // 单独设置数据
    // [SET_SEX](state,actions){
    //     state.sex      = actions.value   
    // },
    // [SET_NAME](state,actions){
    //     state.name     = actions.value   
    // },
    // [SET_IDENTITY](state,actions){
    //     state.cardType = actions.value   
    // },
    // [SET_CARD](state,actions){
    //     state.card     = actions.value   
    // },
    // [SET_BIRTHDAY](state,actions){
    //     state.birthDay = actions.value   
    // },

    // 一起改变
    [SET_ALL](state,actions){
        state.sex      = actions.value.sex  
        state.name     = actions.value.name
        state.cardType = actions.value.cardType
        state.card     = actions.value.card 
        state.birthDay = actions.value.birthDay         
    }
}

let my = (state = homeState,actions) =>{

    TYPES[actions.type]&&TYPES[actions.type](state,actions)

    return {...state}    
}

export default my